#include('./header.html',{active:'page', title:'保存页面'})
<link href="/static/admin/plugins/toggles/toggles.css" rel="stylesheet">
<link href="/static/admin/plugins/md/css/style.css" rel="stylesheet"/>

<div class="row">
    <div class="col-sm-12">
        <h4 class="page-title">
            #if(null != contents)
            编辑页面
            #else
            发布新页面
            #end
        </h4>
    </div>
    <div class="col-md-12">
        <form id="articleForm" role="form" novalidate="novalidate">
            <input type="hidden" name="categories" id="categories"/>
            <input type="hidden" name="cid" value="${contents.cid ?! ''}" id="cid"/>
            <input type="hidden" name="status" value="${contents.status ?! 'publish'}" id="status"/>
            <input type="hidden" name="content" id="content-editor"/>

            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入页面标题" name="title" required=""
                       aria-required="true" value="${contents.title ?! ''}"/>
            </div>

            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入页面访问名" name="slug" required=""
                       aria-required="true" value="${contents.slug ?! ''}"/>
            </div>

            <div class="form-group">
                <textarea style="height: 350px" autocomplete="off" id="text" name="text" class="markdown-textarea">${contents.content ?! ''}</textarea>
            </div>

            <div class="text-right">
                <button type="submit" class="btn btn-primary waves-effect waves-light">保存页面</button>
                <button type="submit" class="btn btn-warning waves-effect waves-light">存为草稿</button>
            </div>
        </form>
    </div>

</div>
#include('./footer.html')

<script src="/static/admin/plugins/md/js/jquery.scrollto.js"></script>
<script src="/static/admin/plugins/md/js/pagedown.js"></script>
<script src="/static/admin/plugins/md/js/pagedown-extra.js"></script>
<script src="/static/admin/plugins/md/js/diff.js"></script>
<script src="/static/admin/plugins/md/js/md.js"></script>

<script src="//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js"></script>
<script src="//cdn.bootcss.com/jquery-validate/1.15.1/jquery.validate.min.js"></script>
<script src="//cdn.bootcss.com/jquery-validate/1.15.1/localization/messages_zh.min.js"></script>
<script>
    // validate the comment form when it is submitted
    $('#articleForm').validate({
        submitHandler: function (form) {
            $('#content-editor').val($('#text').val());
            $("#articleForm #categories").val($('#multiple-sel').val());
            var params = $("#articleForm").serialize();
            var url = $('#articleForm #cid').val() != '' ? '/admin/page/modify' : '/admin/page/publish';
            $.post(url, params, function (result) {
                if (result && result.success) {
                    swal('提示信息', '页面保存成功', 'success');
                    setTimeout(function () {
                        window.location.href = '/admin/page';
                    }, 2000);
                } else {
                    swal("提示消息", result.msg, 'error');
                }
            });
        }
    });

    var textarea = $('#text'),
        toolbar = $('<div class="markdown-editor" id="md-button-bar" />').insertBefore(textarea.parent())
    preview = $('<div id="md-preview" class="md-hidetab" />').insertAfter('.markdown-editor');

    markdown(textarea, toolbar, preview);

</script>

</body>
</html>